package com.emm.yixun.website.listeners;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.emm.yixun.common.model.enums.*;
import com.emm.yixun.customer.service.channel.ChannelSendHttpMessageService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.basic.service.CustomerService;
import com.emm.yixun.basic.service.HaveReceiveRefundService;
import com.emm.yixun.basic.service.MortgageRecordService;
import com.emm.yixun.basic.service.NeedReceiveRefundService;
import com.emm.yixun.basic.service.PayDepositService;
import com.emm.yixun.basic.service.ProjectRoomService;
import com.emm.yixun.basic.service.RoomChangeHistoryService;
import com.emm.yixun.basic.service.SignedService;
import com.emm.yixun.basic.service.SubscribeService;
import com.emm.yixun.common.model.Customer;
import com.emm.yixun.common.model.HaveReceiveRefund;
import com.emm.yixun.common.model.NeedReceiveRefund;
import com.emm.yixun.common.model.PayDeposit;
import com.emm.yixun.common.model.ProjectRoom;
import com.emm.yixun.common.model.Signed;
import com.emm.yixun.common.model.Subscribe;
import com.emm.yixun.common.model.dto.HaveReceiveRefundDto;
import com.emm.yixun.common.model.dto.MortgageRecordDto;
import com.emm.yixun.common.model.dto.NeedReceiveRefundDto;
import com.emm.yixun.common.model.dto.NoticeEntity;
import com.emm.yixun.common.model.dto.PayDepositDto;
import com.emm.yixun.common.model.dto.ProjectRoomDto;
import com.emm.yixun.common.model.dto.RoomChangeHistoryDto;
import com.emm.yixun.common.model.dto.SignedDto;
import com.emm.yixun.common.model.dto.SubscribeDto;
import com.emm.yixun.common.utils.BeanUtil;
import com.emm.yixun.customer.service.impl.app.ActivitiProcessServiceImpl;
import com.emm.yixun.customer.service.impl.app.SpringWebContextUtil;
import com.emm.yixun.system.service.notice.signed.SignedNoticeFacade;

public class SignedListeners implements Serializable, ExecutionListener{
	private static final long serialVersionUID = 4995605219601432269L;
	
	@Override
	public void notify(DelegateExecution execution) throws Exception {
		String id=execution.getProcessBusinessKey();
		String processInstanceId=execution.getProcessInstanceId();
		SignedService signedService=getSignedService();
		ProjectRoomService projectRoomService=getProjectRoomService();
		PayDepositService payDepositService=getPayDepositService();
		SubscribeService subscribeService=getSubscribeService();
		NeedReceiveRefundService needReceiveRefundService = getNeedReceiveRefundService();
		HaveReceiveRefundService haveReceiveRefundService = getHaveReceiveRefundService();
		Signed signed=signedService.selectById(Long.valueOf(id));
		if(null==signed){
			throw new Exception("签约记录不存在");
		}
		if(getActivitiProcessServiceImpl().isCheckPass(processInstanceId)){
			/**
			 * 1.修改认购记录审核状态为通过   
			 * 2.记录房源变更记录
			 * 3.记录应收款
			 * 4.内部转账(认筹、认购已收款转签约已收)
			 * 5.生成按揭记录
			 * 6.更改客户交易状态为认筹，判断是否多套交易并更新状态
			 * 7.推送消息
			 */
			//1.修改认筹记录审核状态为通过   
			SignedDto updateDto = new SignedDto();
			updateDto.setId(Long.valueOf(id));
			updateDto.setAuditStatus(AuditStatusEnum.SUCCESS.getNo());
			updateDto.setCheckDate(new Date());
			signedService.update(updateDto);
			if(signed.getSubscribeId()!=null&&!signed.getSubscribeId().equals("")){
				SubscribeDto subscribeDto = new SubscribeDto();
				subscribeDto.setBusinessStatus("2");//认购转签约
				subscribeDto.setId(signed.getSubscribeId());
				subscribeService.update(subscribeDto);
			}
			if(signed.getPayDepositId()!=null&&!signed.getPayDepositId().equals("")){
				PayDepositDto payDepositDto = new PayDepositDto();
				payDepositDto.setBusinessStatus("3");//认筹转签约
				payDepositDto.setId(signed.getPayDepositId());
				payDepositService.update(payDepositDto);
			}
			
			//2.记录房源变更记录
			RoomChangeHistoryDto dto=new RoomChangeHistoryDto();
			dto.setRoomId(signed.getRoomId());
			dto.setBusinessDynamics("签约");
			dto.setRemark("房源由【可售】转为【签约】");
			if(StringUtils.isNotBlank(signed.getSubscribeCode())){
				dto.setRemark("房源由【认购】转为【签约】");
			}
			if(StringUtils.isNotBlank(signed.getPayDepositCode())){
				dto.setRemark("房源由【小定】转为【签约】");
			}
			dto.setBusinessHref("/customer/signed/toView?id="+signed.getId()+"&returnUrl=,marketing,room,index");
    		dto.setMerchantId(signed.getMerchantId());
    		dto.setAccessCode(signed.getAccessCode());
    		dto.setCreateUserId(signed.getCreateUserId());
    		dto.setUserCode(signed.getUserCode());
    		dto.setDelFlag("0");
    		dto.setUpdateUserId(signed.getUpdateUserId());
    		dto.setUpdateTime(new Date());
    		RoomChangeHistoryDto rchSaveResponse=getRoomChangeHistoryService().create(dto);
    		if(rchSaveResponse == null){
    			throw new Exception("房源变更记录表新增失败!");
    		}
    		/*
			 * ym：记录应收款
			 * */
    		saveNeedReceive(signed,needReceiveRefundService);
    		/*
			 * ym：记录应收款
			 * */
			//3.查询签约应收并生成按揭记录
    		NeedReceiveRefundDto needReceiveRefundDto=new NeedReceiveRefundDto();
    		needReceiveRefundDto.setDocType("0");
    		needReceiveRefundDto.setBusinessType("2");
    		needReceiveRefundDto.setRelationId(signed.getId());
    		List<NeedReceiveRefund> responseList=needReceiveRefundService.selectListByDto(needReceiveRefundDto);
			if(null!=responseList && responseList.size() > 0){
				/*
				 * ym：内部转账
				 * */
				conversionHaveReceive(signed, responseList,subscribeService,haveReceiveRefundService);
				/*
				 * ym：内部转账
				 * */
				MortgageRecordService mortgageRecordService=getMortgageRecordService();
				CustomerService customerService=getCustomerService();
				for(NeedReceiveRefund nff : responseList){
					if(nff.getPaymentMethod().equals(PaymentMethodEnum.LUMP_SUM.getNo()) || nff.getPaymentMethod().equals(PaymentMethodEnum.INSTALLMENT_PAYMENT.getNo())){
						continue;
					}
					String housingFundTyp=nff.getHousingFundType();
					if(housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_10.getNo()) || housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_17.getNo()) || housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_6.getNo())){
						continue;
					}
					MortgageRecordDto mortgageRecordDto=new MortgageRecordDto();
					mortgageRecordDto.setNeedId(nff.getId());
					mortgageRecordDto.setSignedId(signed.getId());
					mortgageRecordDto.setRoomId(signed.getRoomId());
					mortgageRecordDto.setCustomerId(signed.getCustomerId());
					mortgageRecordDto.setProjectId(signed.getProjectId());
					mortgageRecordDto.setBusinessFlag(nff.getBusinessFlag());
					mortgageRecordDto.setHousingFundType(nff.getHousingFundType());
					ProjectRoom projectRoom=projectRoomService.selectById(signed.getRoomId());
					if(projectRoom != null){
						mortgageRecordDto.setRoomName(projectRoom.getCombinedName());
					}else{
						mortgageRecordDto.setRoomName("未知");
					}
					Customer customerResponse=customerService.selectById(signed.getCustomerId());
					if(customerResponse != null){
						mortgageRecordDto.setCustomerName(customerResponse.getCustomerName());
					}else{
						mortgageRecordDto.setCustomerName("未知");
					}
					
					mortgageRecordDto.setSignedDate(signed.getDidTime());
					mortgageRecordDto.setSignAmount(signed.getSignAmount());
					//按揭金额
					mortgageRecordDto.setMortgageAmount(nff.getTotalReceivablesAmount());
					mortgageRecordDto.setMortgageReceivedStatus("0");
					mortgageRecordDto.setMortgageCheckStatus("0");
					mortgageRecordDto.setProcessStatus("0");
					
					mortgageRecordDto.setMerchantId(signed.getMerchantId());
					mortgageRecordDto.setAccessCode(signed.getAccessCode());
					mortgageRecordDto.setCreateUserId(signed.getCreateUserId());
					mortgageRecordDto.setUserCode(signed.getUserCode());
					mortgageRecordDto.setDelFlag("0");
					mortgageRecordDto.setUpdateUserId(signed.getUpdateUserId());
					mortgageRecordDto.setUpdateTime(new Date());
					mortgageRecordDto.setReceivablesFunds(nff.getReceivablesFunds());
					MortgageRecordDto response=mortgageRecordService.create(mortgageRecordDto);
					if(response ==null){
		    			throw new Exception("按揭记录表新增失败!");
		    		}
				}
			}
			
			/**
			 * 4.更改客户交易状态为认购，判断是否多套交易并更新状态 todo
			 * @param bugType 业务类型： 1 认筹、2 认购、3 签约
			 * @param busId 对应业务类型Id
			 * @param customerId 客户Id
			 * @param userId 用户Id
			 */
			getCustomerService().getCustomerEntity("3", Long.valueOf(id),signed.getCustomerId() , signed.getUpdateUserId());
			
			/**
			 * （签约审核通过）推送消息到app
			 * @author ny
			 * @param param noticeType 提醒类型, noticeBusinessId 业务主键Id
			 * @return 【${auditStatus}】房号：${roomName}；客户：${customer};
			 */
			NoticeEntity noticeEntity = new NoticeEntity();
			noticeEntity.setNoticeBusinessId(signed.getId());
			noticeEntity.setNoticeType("6");
			noticeEntity.setProcessInstanceId(processInstanceId);
			noticeEntity.setAudStatus("3");
			getSignedNoticeFacade().createSignedNotice(noticeEntity);

			/**
			 * 推送到渠道
			 */
			getChannelSendHttpMessageService().sendTransaction(signed.getId(), TransTypeEnum.SIGNED.getNo(), false);
			
		}else{
			/**
			 * 1.修改签约记录审核状态为不通过
			 * 2.修改房源状态为未售或者认筹
			 */

			SignedDto updateDto = new SignedDto();
			updateDto.setId(signed.getId());
			updateDto.setAuditStatus(AuditStatusEnum.REJECT.getNo());
			updateDto.setCheckDate(new Date());
			signedService.update(updateDto);
			
			//认购转签约：判断认购ID是否存在，存在情况下，判断该房间是否还有认购记录，有则房间状态回到认购，否则回到可售状态，不存在情况下，往下判断
			if(signed.getSubscribeId()!=null&&!signed.getSubscribeId().equals("")){
				SubscribeDto subscribeDto = new SubscribeDto();
				subscribeDto.setM_auditStatus(" and t.audit_status in (1,3)");
				subscribeDto.setRoomId(signed.getRoomId());
				List<Subscribe> responseList = subscribeService.selectListByDto(subscribeDto);
				if(responseList == null || responseList.size() == 0){
					ProjectRoomDto projectRoomDto = new ProjectRoomDto();
					projectRoomDto.setId(signed.getRoomId());
					projectRoomDto.setRoomStatus(RoomStatusEnum.VENDIBILITY.getNo());//可售
					Integer responseRoomDto=projectRoomService.update(projectRoomDto);
					if(responseRoomDto< 1){
						throw new Exception("房间状态为可售出错");
					}
				}else{
					ProjectRoomDto projectRoomDto = new ProjectRoomDto();
					projectRoomDto.setId(signed.getRoomId());
					projectRoomDto.setRoomStatus(RoomStatusEnum.BUY.getNo());//认购
					Integer responseRoomDto=projectRoomService.update(projectRoomDto);
					if(responseRoomDto< 1){
						throw new Exception("房间状态为认购出错");
					}
				}
			}else if(signed.getPayDepositId()!=null&&!signed.getPayDepositId().equals("")){
				//认筹转签约：判断认筹ID是否存在，存在情况下，判断该房间是否还有认筹记录，有则房间状态回到认筹，否则回到可售状态，不存在情况下，往下判断
				PayDepositDto payDepositDto = new PayDepositDto();
				payDepositDto.setM_auditStatus(" and t.audit_status in (1,3)");
				payDepositDto.setRoomId(signed.getRoomId());
				List<PayDeposit> responseList = payDepositService.selectListByDtoJ(payDepositDto);
				if(responseList == null || responseList.size() == 0){
					ProjectRoomDto projectRoomDto = new ProjectRoomDto();
					projectRoomDto.setId(signed.getRoomId());
					projectRoomDto.setRoomStatus(RoomStatusEnum.VENDIBILITY.getNo());//可售
					Integer responseRoomDto=projectRoomService.update(projectRoomDto);
					if(responseRoomDto< 1){
						throw new Exception("房间状态为可售出错");
					}
				}else{
					ProjectRoomDto projectRoomDto = new ProjectRoomDto();
					projectRoomDto.setId(signed.getRoomId());
					projectRoomDto.setRoomStatus(RoomStatusEnum.RESERVE.getNo());//认筹
					Integer responseRoomDto=projectRoomService.update(projectRoomDto);
					if(responseRoomDto< 1){
						throw new Exception("房间状态为认筹出错");
					}
				}
			} 
			
			//直接签约：判断该房间是否还有认筹记录，有则房间状态回到认筹，否则回到可售状态
			if(signed.getSubscribeId()==null&&signed.getPayDepositId()==null){
				PayDepositDto payDepositDto = new PayDepositDto();
				payDepositDto.setM_auditStatus(" and t.audit_status in (1,3)");
				payDepositDto.setRoomId(signed.getRoomId());
				List<PayDeposit> responseList = payDepositService.selectListByDto(payDepositDto);
				if(responseList == null || responseList.size() == 0){
					ProjectRoomDto projectRoomDto = new ProjectRoomDto();
					projectRoomDto.setId(signed.getRoomId());
					projectRoomDto.setRoomStatus(RoomStatusEnum.VENDIBILITY.getNo());//可售
					Integer responseRoomDto=projectRoomService.update(projectRoomDto);
					if(responseRoomDto< 1){
						throw new Exception("房间状态为可售出错");
					}
				}else{
					ProjectRoomDto projectRoomDto = new ProjectRoomDto();
					projectRoomDto.setId(signed.getRoomId());
					projectRoomDto.setRoomStatus(RoomStatusEnum.RESERVE.getNo());//认筹
					Integer responseRoomDto=projectRoomService.update(projectRoomDto);
					if(responseRoomDto< 1){
						throw new Exception("房间状态为认筹出错");
					}
				}
			}
			
			/**
			 * （签约审核不通过）推送消息到app
			 * @author ny
			 * @param param noticeType 提醒类型, noticeBusinessId 业务主键Id
			 * @return 【${auditStatus}】房号：${roomName}；客户：${customer};
			 */
			NoticeEntity noticeEntity = new NoticeEntity();
			noticeEntity.setNoticeBusinessId(signed.getId());
			noticeEntity.setNoticeType("6");
			noticeEntity.setProcessInstanceId(processInstanceId);
			noticeEntity.setAudStatus("2");
			getSignedNoticeFacade().createSignedNotice(noticeEntity);
		}
	}
	
	private void conversionHaveReceive(Signed signed,List<NeedReceiveRefund> needList,SubscribeService subscribeService,HaveReceiveRefundService haveReceiveRefundService) {
		List<HaveReceiveRefund> convertList = new ArrayList<HaveReceiveRefund>();
		// 查询认筹已收
		// 查询认购已收
		// 绑定签约应收第一条
		if (signed.getSubscribeId() != null) {
			Subscribe subscribe=subscribeService.selectById(signed.getSubscribeId());
			// 认购转签约
			HaveReceiveRefundDto haveReceiveRefundDto = new HaveReceiveRefundDto();
			haveReceiveRefundDto.setRelationId(subscribe.getId());
			// 已收
			haveReceiveRefundDto.setDocType("0");
			// 认购
			haveReceiveRefundDto.setReceivablesType("1");
			// 正常
			haveReceiveRefundDto.setTransferStatus("0");
			List<HaveReceiveRefund> responseHrrList=haveReceiveRefundService.selectListByDto(haveReceiveRefundDto);
			if (null != responseHrrList && responseHrrList.size() > 0) {
				for (HaveReceiveRefund have : responseHrrList) {
					if (!have.getBusinessFlag().equals(
							BusinessFlagEnum.BUSINESSFLAG_11.getNo())) {
						convertList.add(have);
					}
				}
			}

		} else if (signed.getPayDepositId() != null) {
			// 认筹转认购
			HaveReceiveRefundDto haveReceiveRefundDto = new HaveReceiveRefundDto();
			haveReceiveRefundDto.setRelationId(signed.getPayDepositId());
			// 已收
			haveReceiveRefundDto.setDocType("0");
			// 认筹
			haveReceiveRefundDto.setReceivablesType("0");
			List<HaveReceiveRefund> responseHrrList=haveReceiveRefundService.selectListByDto(haveReceiveRefundDto);
			if (null != responseHrrList && responseHrrList.size() > 0) {
				for (HaveReceiveRefund have : responseHrrList) {
					if (!have.getBusinessFlag().equals(
							BusinessFlagEnum.BUSINESSFLAG_11.getNo())) {
						convertList.add(have);
					}
				}

			}
		}

		// 查找应收
		NeedReceiveRefund tempNeedReceive = null;
		for (NeedReceiveRefund nrr : needList) {
			String housingFundTyp = nrr.getHousingFundType();
			if (housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_5.getNo())
					|| housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_6
							.getNo())
					|| housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_10
							.getNo())
					|| housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_12
							.getNo())
					|| housingFundTyp.equals(HousingFundTypeEnum.FUNDTYPE_17
							.getNo())) {
				tempNeedReceive = nrr;
				break;
			}
		}
		if (null != tempNeedReceive && convertList.size() > 0) {
			try {
				HaveReceiveRefund haveReceiveRefund = null;
				BigDecimal totalRealAmount=BigDecimal.ZERO;
				for (HaveReceiveRefund hrr : convertList) {
					totalRealAmount=totalRealAmount.add(hrr.getRealAmount());
					if (null == haveReceiveRefund)
						haveReceiveRefund = hrr;
				}

				// 转到应收下
				HaveReceiveRefundDto haveReceiveRefundDto = new HaveReceiveRefundDto();
				haveReceiveRefundDto = BeanUtil.convert2T(haveReceiveRefundDto,
						haveReceiveRefund);
				haveReceiveRefundDto.setId(null);
				haveReceiveRefundDto.setRelationId(signed.getId());
				haveReceiveRefundDto.setReceivablesType("2");
				haveReceiveRefundDto.setReceivablesId(tempNeedReceive.getId());
				haveReceiveRefundDto.setHousingFundType(tempNeedReceive
						.getHousingFundType());
				if (signed.getSubscribeId() != null) {
					// 认购转签约
					haveReceiveRefundDto
							.setBusinessFlag(BusinessFlagEnum.BUSINESSFLAG_13
									.getNo());
				} else if (signed.getPayDepositId() != null) {
					// 认筹转签约
					haveReceiveRefundDto
							.setBusinessFlag(BusinessFlagEnum.BUSINESSFLAG_12
									.getNo());
				}
				haveReceiveRefundDto.setTransferStatus("0");
				haveReceiveRefundDto.setBillCode("");
				haveReceiveRefundDto.setRealAmount(totalRealAmount);
				haveReceiveRefundDto.setStatementId(null);
				haveReceiveRefundDto.setStatementType(Long.valueOf(StatementTypeEnum.TRANSFER.getNo()));
				haveReceiveRefundDto.setStatementDate(new Date());
				haveReceiveRefundDto.setRemark("系统内部转账");
				haveReceiveRefundDto.setCreateTime(new Date());
				HaveReceiveRefundDto hrrResponse= haveReceiveRefundService.create(haveReceiveRefundDto);
				if(hrrResponse == null){
					throw new Exception("转已收款出错");
				}
				
				for (HaveReceiveRefund hrr : convertList) {
					// 原记录更新为转出
					HaveReceiveRefundDto updateDto = new HaveReceiveRefundDto();
					updateDto.setId(hrr.getId());
					updateDto.setTransferStatus("1");
					Integer count = haveReceiveRefundService.update(updateDto);
					if(count < 1){
						throw new Exception("转已收款出错");
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	
	private void saveNeedReceive(Signed signed,NeedReceiveRefundService needReceiveRefundService) {
		String extraInformation=signed.getExtraInformation();
		if(StringUtils.isBlank(extraInformation)){
			return;
		}
		JSONObject object=JSON.parseObject(extraInformation);
		JSONArray needReceive = object.getJSONArray("paymentDetails");
		if (null != needReceive && needReceive.size() > 0) {
			for (int i = 0; i < needReceive.size(); i++) {
				NeedReceiveRefundDto needReceiveRefundDto = JSONObject.parseObject(needReceive.getJSONObject(i).toJSONString(), NeedReceiveRefundDto.class);
				needReceiveRefundDto.setRelationId(signed.getId());
				needReceiveRefundDto.setBusinessType("2");
				needReceiveRefundDto.setCustomerId(signed.getCustomerId());
				needReceiveRefundDto.setRoomId(signed.getRoomId());
				needReceiveRefundDto.setStatus("1");
				needReceiveRefundDto.setPostponedStatus("0");
				needReceiveRefundDto.setDocType("0");
				needReceiveRefundDto.setRemark("签约收款");
				needReceiveRefundDto.setMerchantId(signed.getMerchantId());
				needReceiveRefundDto.setPaymentMethod(signed.getPaymentMethod());
				needReceiveRefundDto.setUserCode(signed.getUserCode());
				needReceiveRefundDto.setAccessCode(signed.getAccessCode());
				needReceiveRefundDto.setCreateUserId(signed.getCreateUserId());
				needReceiveRefundDto.setDelFlag("0");
				needReceiveRefundDto.setUpdateUserId(signed.getUpdateUserId());
				needReceiveRefundDto.setUpdateTime(new Date());
				needReceiveRefundService.create(needReceiveRefundDto);
			}
		}
	}
	
	private SignedNoticeFacade getSignedNoticeFacade(){
		return (SignedNoticeFacade)SpringWebContextUtil.getApplicationContext().getBean("signedNoticeFacade");
	}
	
	private ProjectRoomService getProjectRoomService(){
		return (ProjectRoomService)SpringWebContextUtil.getApplicationContext().getBean("projectRoomService");
	}
	
	private SignedService getSignedService(){
		return (SignedService)SpringWebContextUtil.getApplicationContext().getBean("signedService");
	}
	
	private PayDepositService getPayDepositService(){
		return (PayDepositService)SpringWebContextUtil.getApplicationContext().getBean("payDepositService");
	}
	
	private SubscribeService getSubscribeService(){
		return (SubscribeService)SpringWebContextUtil.getApplicationContext().getBean("subscribeService");
	}
	
	private ActivitiProcessServiceImpl getActivitiProcessServiceImpl(){
		return (ActivitiProcessServiceImpl)SpringWebContextUtil.getApplicationContext().getBean("activitiProcessServiceImpl");
	}
	
	private RoomChangeHistoryService getRoomChangeHistoryService(){
		return (RoomChangeHistoryService)SpringWebContextUtil.getApplicationContext().getBean("roomChangeHistoryService");
	}
	
	private NeedReceiveRefundService getNeedReceiveRefundService(){
		return (NeedReceiveRefundService)SpringWebContextUtil.getApplicationContext().getBean("needReceiveRefundService");
	}
	
	private HaveReceiveRefundService getHaveReceiveRefundService(){
		return (HaveReceiveRefundService)SpringWebContextUtil.getApplicationContext().getBean("haveReceiveRefundService");
	}
	
	private MortgageRecordService getMortgageRecordService(){
		return (MortgageRecordService)SpringWebContextUtil.getApplicationContext().getBean("mortgageRecordService");
	}
	
	private CustomerService getCustomerService(){
		return (CustomerService)SpringWebContextUtil.getApplicationContext().getBean("customerService");
	}

	private ChannelSendHttpMessageService getChannelSendHttpMessageService() {
		return (ChannelSendHttpMessageService) SpringWebContextUtil.getApplicationContext()
				.getBean("channelSendHttpMessageService");
	}

}
